<?php

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

class Makul_Model extends Model {

    public function __construct() {
        parent::__construct();
    }

    public function add_makul($data) {


        $check = $this->db->prepare("select nama from universitas where nama=:nama");

        $check->execute(array(
            ':nama' => $data['nama']
        ));

//        print_r($data);
        $result = $check->rowCount();
//        var_dump($result);

        if ($result > 0) {
//            echo 'data sudah ada';
        } else {
            $sth = $this->db->prepare
                    (
                    "INSERT INTO universitas 
                (nama)
                VALUES 
                (:nama)"
            );
            $sth->execute(array(
                ':nama' => $data['nama']
            ));
        }
    }

    public function list_makul() {
        $nrp = session::get('nrp');
        $sth = $this->db->prepare("select kd_univ,kd_jurusan from user_detail where nrp = :nrp ");
        $sth->execute(array(
            ':nrp' => $nrp
        ));

        $data = $sth->fetch();

        $kd_univ = $data['kd_univ'];
        $kd_jurusan = $data['kd_jurusan'];

        $sth2 = $this->db->prepare("select kd_makul from makul 
            where 
            kd_univ = :kd_univ 
            and 
            kd_jurusan = :kd_jurusan");

        $sth2->execute(array(
            ':kd_univ' => $kd_univ,
            ':kd_jurusan' => $kd_jurusan
        ));

        $data2 = $sth2->fetchAll();
        return $data2;

//        print_r($data);
    }

}

?>
